﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI;
using Baosight.ZNH.ZMCommon;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZP.UI.PopWindows;
using Microsoft.Practices.Unity;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZP.UI.Utils;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZP.UI
{
    /// <summary>
    /// 资源组从表
    /// </summary>
    /// Title:ZP23
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 梁琦
    /// Version: 1.0
    /// History:
    ///       2012-10-18  梁琦   [创建]
    ///  
    public partial class ZP23 : EFViewCmes
    {
        private TypeBlock typeBlock = new TypeBlock();

        public ZP23()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(typeBlock.GetType());
            base.Initialize(initData);
        }

        /// <summary>
        /// 列表中修改、删除前设置属性、参数
        /// 传递到后台代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.Resgrid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 点击新增按钮，弹出新增页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

       public override void OnInsertButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set(EIConstants.ServiceNameKey, "ZP23");
            eiInfo.Set(EIConstants.MethodNameKey, "queryRes");
            eiInfo.Set("Name", this.Name.Value);
            this.Submit(eiInfo, QueryCompleted);
        }

       /// <summary>
       /// 点击新增按钮，弹出新增页面时查询
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        private void QueryCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status != -1)
            {
                e.EIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.zp.resType"));
                ResInsert view = new ResInsert("insert");               
                view.EIDataContext = new Platform.Core.UI.EIDataContext();
                view.EIDataContext.Update(e.EIInfo);

                view.Name.Value = this.Name.Value;

                CmesWindows _popup = new CmesWindows();//构造一个弹出页面
                _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
                _popup.Header = "添加资源";//设置Title
                _popup.Content = view;//让新增页面在弹出窗口显示
                _popup.Closed += new EventHandler<WindowClosedEventArgs>(CmesWindow_Closed);
                _popup.ShowDialog();//模态显示弹出窗口
            }
            else
            {
                BaseTools.OpenEFWindowAlert("查询失败:" + e.EIInfo.Msg, null);
                TempButton.IsEnabled = true;
            }
        }
    

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmesWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                //刷新Grid区域
                this.Resgrid.Refresh();
            }

            //按钮生效
            base.TempButtonOpen(true);

        }

        /// <summary>
        /// 点击删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnDeleteButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnDeleteButtonClick(sender, e);
        }



  
    }
}
